<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Beyond Basic Conversions</title>
<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="Chapter 1. Boost.Convert 2.0">
<link rel="up" href="../index.html" title="Chapter 1. Boost.Convert 2.0">
<link rel="prev" href="performance/the_bigger_picture.html" title="The Bigger Picture">
<link rel="next" href="converters_detail.html" title="Converters in Detail">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td>
<td align="center"><a href="../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="performance/the_bigger_picture.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="converters_detail.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="boost_convert.other_conversions"></a><a class="link" href="other_conversions.html" title="Beyond Basic Conversions">Beyond Basic Conversions</a>
</h2></div></div></div>
<p>
      An interesting (and yet to be fully explored) property of the described design
      is that <span class="emphasis"><em>Boost.Convert</em></span> is not limited to string-to-type
      and type-to-string conversions. The <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">convert</span><span class="special">()</span></code> interface is type-agnostic and the plugged-in
      converter ultimately dictates what type transformations are available. Consequently,
      a wide range of conversion/transformation-related tasks can be addressed and
      <span class="emphasis"><em>deployed uniformly</em></span> by plugging-in special-purpose converters.
    </p>
<p>
      As an experiment, the code below (taken from <span class="emphasis"><em>test/encryption.cpp</em></span>)
      does not do type conversion. Instead, it applies a string transformation:
    </p>
<pre class="programlisting"><span class="identifier">string</span> <span class="identifier">encrypted</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">convert</span><span class="special">&lt;</span><span class="identifier">string</span><span class="special">&gt;(</span><span class="string">"ABC"</span><span class="special">,</span> <span class="identifier">my_cypher</span><span class="special">).</span><span class="identifier">value</span><span class="special">();</span>
<span class="identifier">string</span> <span class="identifier">decrypted</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">convert</span><span class="special">&lt;</span><span class="identifier">string</span><span class="special">&gt;(</span><span class="identifier">encrypted</span><span class="special">,</span> <span class="identifier">my_cypher</span><span class="special">).</span><span class="identifier">value</span><span class="special">();</span>

<span class="identifier">BOOST_ASSERT</span><span class="special">(</span><span class="identifier">encrypted</span> <span class="special">==</span> <span class="string">"123"</span><span class="special">);</span>
<span class="identifier">BOOST_ASSERT</span><span class="special">(</span><span class="identifier">decrypted</span> <span class="special">==</span> <span class="string">"ABC"</span><span class="special">);</span>
</pre>
<p>
      The original "ABC" string is "encrypted" as "123"
      first and then "123" is "decrypted" back to its original
      "ABC" form.
    </p>
<p>
      Similarly, I personally do not immediately see as objectionable string-transformations
      like:
    </p>
<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">u8string</span> <span class="identifier">utf8</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">convert</span><span class="special">&lt;</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">u8string</span><span class="special">&gt;(</span><span class="identifier">utf32_str</span><span class="special">,</span> <span class="identifier">cnv</span><span class="special">);</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">u8string</span> <span class="identifier">utf8</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">convert</span><span class="special">&lt;</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">u8string</span><span class="special">&gt;(</span><span class="identifier">mbcs_str</span><span class="special">,</span> <span class="identifier">cnv</span><span class="special">);</span>
</pre>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2009-2020 Vladimir Batov<p>
        Distributed under the Boost Software License, Version 1.0. See copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>.
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="performance/the_bigger_picture.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="converters_detail.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
